//# sourceURL=http://uMapApp/Module/WorkManageModule/StorehouseModule
define([
    "mhjs/mhjs",
    "uMap/uMap",
    "uEarth/uEarth",
    "../Module"
    , "../../UI/Panel/FloatPanel"
    , "../../UI/Panel/PanelBlock/PanelBlock"
    , "../../UI/Panel/PanelBlock/TreeBlock"
    , "../../UI/Panel/PanelBlock/TableBlock"
    , "../../UI/Panel/PanelBlock/ChartBlock"
    , "../../UI/Tree/Tree"
    , "../../UI/Layer"
    , "../../UI/TopMenu/TopMenus"
    , "../../UI/Panel/Panel"
], function (
    mhjs,
    uMap,
    uEarth,
    Module
    , FloatPanel
    , PanelBlock
    , TreeBlock
    , TableBlock
    , ChartBlock
    , Tree
    , Layer
    , TopMenus
    , Panel
) {

    function StorehouseModule(option) {

        var _this = this;

        Module.call(_this, option);

        _this.title = "智能仓储";
        _this.icon = _this.app.icons.home;

        _this.heightFix = 11.1;

        _this.layer = new Layer({
            "app": _this.app
        });

        _this.layer.pointPrimitives = new uMap.PointPrimitiveCollection();
        _this.layer.primitives.add(_this.layer.pointPrimitives.object);

        _this.layer.labelPrimitives = new uMap.LabelCollection();
        _this.layer.primitives.add(_this.layer.labelPrimitives.object);

        _this.layer.billboardPrimitives = new uMap.BillboardCollection();
        _this.layer.primitives.add(_this.layer.billboardPrimitives.object);

        _this.panels = {};


        _this.panels.infoPanel = new FloatPanel({
            "class"     : "leftPanel scModule scPanel top newPanel",
            "showMinMax": true,
            "title"     : "仓库简介"
        });

        _this.panels.infoPanel.infoBlock = new PanelBlock({
            "title"  : "仓库简介",
            "content": "　　为统一停放各类养护设备及冬防物资, 公司新建车库800平方，设5间库房，分别为：小型设备仓库、冬防物资仓库、标牌锥筒仓库、车辆备件仓库和应急物资仓库。合计摆放融雪剂10余吨，锥桶200余个，标志标牌2套等冬防物资。"
        });

        _this.panels.infoPanel.append(
            _this.panels.infoPanel.infoBlock
        );

        _this.panels.nowStaPanel = new FloatPanel({
            "class"     : "leftPanel scModule scPanel mid newPanel",
            "showMinMax": true,
            "title"     : "仓库现存量统计"
        });

        _this.panels.nowStaPanel.nowStaBlock = new ChartBlock({
            "title": "仓库现存量统计",
            "chart": {
                "height"     : 270,
                "width"      : 358,
                "chartOption": {
                    grid   : {
                        left        : "0%",
                        right       : "0%",
                        bottom      : "0%",
                        containLabel: true
                    },
                    tooltip: {
                        trigger        : "item",
                        backgroundColor: "rgb(1, 20, 30)",
                        borderColor    : "#333",
                        textStyle      : {
                            color: "#fff"
                        },
                        confine        : true
                    },
                    series : {
                        type  : "pie",
                        center: ["50%", "50%"],
                        radius: "50%",
                        label : {
                            formatter  : "{b}: {c}",
                            bleedMargin: 1,
                            color      : "#fff"
                        }
                    }
                }
            }
        });

        _this.panels.nowStaPanel.append(
            _this.panels.nowStaPanel.nowStaBlock
        );

        _this.panels.agePanel = new FloatPanel({
            "class"     : "rightPanel scModule scPanel top newPanel",
            "showMinMax": true,
            "title"     : "库存库龄预警"
        });

        _this.panels.agePanel.ageBlock = new TableBlock({
            "title": "库存库龄预警"
        });

        _this.panels.agePanel.append(
            _this.panels.agePanel.ageBlock
        );

        _this.panels.usePanel = new FloatPanel({
            "class"     : "rightPanel scModule scPanel mid newPanel",
            "showMinMax": true,
            "title"     : "物料领用排名"
        });

        _this.panels.usePanel.useBlock = new TableBlock({
            "title": "物料领用排名"
        });

        _this.panels.usePanel.append(
            _this.panels.usePanel.useBlock
        );

        _this.panels.nowDetailPanel = new FloatPanel({
            "class"    : "rightPanel scModule newPanel",
            "showClose": true
        });

        _this.panels.nowDetailPanel.nowDetailBlock = new TableBlock({
            "title": "仓库实时库存"
        });

        _this.panels.nowDetailPanel.nowDetailBlock.exprotButton = new mhjs.Div({"class": "button"});
        _this.panels.nowDetailPanel.nowDetailBlock.exprotButton.text("导出");

        _this.panels.nowDetailPanel.nowDetailBlock.exprotButton.on("click", function () {
            _this.panels.nowDetailPanel.nowDetailBlock.exportXls("仓库实时库存.xls");
        });

        _this.panels.nowDetailPanel.nowDetailBlock.addButton(_this.panels.nowDetailPanel.nowDetailBlock.exprotButton);

        _this.panels.nowDetailPanel.append(
            _this.panels.nowDetailPanel.nowDetailBlock
        );


        _this.treeBlock = new TreeBlock({
            "title"   : "快速定位",
            "class"   : "moduleTreeBlock",
            "autoOpen": true
        });


        _this.treeBlock.tree.title = "智能仓储";

        _this.loadFeaturesViewports(function () {
            _this.treeBlock.tree.list = _this.renderFeaturesViewportsTree(_this.featuresViewports);
            _this.treeBlock.tree.openChild();
        });


        _this.app.ui.layout.left
            .append(_this.panels.infoPanel)
            .append(_this.panels.nowStaPanel)
        ;
        _this.app.ui.layout.right
            .append(_this.panels.agePanel)
            .append(_this.panels.usePanel)
            .append(_this.panels.nowDetailPanel)
        ;

        _this.viewport = {
            "center": {
                "longitude": 120.72436132412967, "latitude": 31.045116062095875, "height": 9.843357916148804
            }, "hpr": {
                "heading": 358.69412208703835, "pitch": -30.742840245385143, "range": 118.43901628397361
            }
        };

        _this.featureGroups = {
            "top" : {
                "ids": [
                    "a3c65c2974270fd093ee8a9bf8ae7d0b",
                    "d1fe173d08e959397adf34b1d77e88d7",
                    "5878a7ab84fb43402106c575658472fa",
                    "9766527f2b5d3e95d4a733fcfb77bd7e",
                    "35f4a8d465e6e1edc05f3d8ab658c551",
                    "006f52e9102a8d3be2fe5614f42ba989",
                    "9c838d2e45b2ad1094d42f4ef36764f6",
                    "f033ab37c30201f73f142449d037028d",
                    "7e7757b1e12abcb736ab9a754ffb617a",
                    "f90f2aca5c640289d0a29417bcb63a37",
                    "28dd2c7955ce926456240b2ff0100bde",
                    "3636638817772e42b59d74cff571fbb3",
                    "fa7cdfad1a5aaf8370ebeda47a1ff1c3",
                    "53c3bce66e43be4f209556518c2fcb54",
                    "49182f81e6a13cf5eaa496d51fea6406",
                    "9fd81843ad7f202f26c1a174c7357585",
                    "ef0d3930a7b6c95bd2b32ed45989c61f",
                    "34ed066df378efacc9b924ec161e7639",
                    "11b9842e0a271ff252c1903e7132cd68",
                    "496e05e1aea0a9c4655800e8a7b9ea28",
                    "8e98d81f8217304975ccb23337bb5761",
                    "eddea82ad2755b24c4e168c5fc2ebd40",
                    "9dfcd5e558dfa04aaf37f137a1d9d3e5",
                    "839ab46820b524afda05122893c2fe8e",
                    "918317b57931b6b7a7d29490fe5ec9f9",
                    "0e01938fc48a2cfb5f2217fbfb00722d",
                    "0f49c89d1e7298bb9930789c8ed59d48",
                    "e3796ae838835da0b6f6ea37bcf8bcb7",
                    "d395771085aab05244a4fb8fd91bf4ee",
                    "20f07591c6fcb220ffe637cda29bb3f6",
                    "63923f49e5241343aa7acb6a06a751e7",
                    "4734ba6f3de83d861c3176a6273cac6d",
                    "7f100b7b36092fb9b06dfb4fac360931",
                    "03c6b06952c750899bb03d998e631860",
                    "c24cd76e1ce41366a4bbe8a49b02a028",
                    "fe131d7f5a6b38b23cc967316c13dae2",
                    "d96409bf894217686ba124d7356686c9",
                    "cfa0860e83a4c3a763a7e62d825349f7",
                    "b1a59b315fc9a3002ce38bbe070ec3f5",
                    "8c19f571e251e61cb8dd3612f26d5ecf",
                    "e56954b4f6347e897f954495eab16a88",
                    "eda80a3d5b344bc40f3bc04f65b7a357",
                    "06138bc5af6023646ede0e1f7c1eac75"
                ]
            },
            "room": {
                "ids": [
                    "a97da629b098b75c294dffdc3e463904",
                    "32b30a250abd6331e03a2a1f16466346",
                    "71ad16ad2c4d81f348082ff6c4b20768",
                    "43fa7f58b7eac7ac872209342e62e8f1",
                    "31839b036f63806cba3f47b93af8ccb5",
                    "3988c7f88ebcb58c6ce932b957b6f332",
                    "42a0e188f5033bc65bf8d78622277c4e",
                    "7f1de29e6da19d22b51c68001e7e0e54",
                    "02522a2b2726fb0a03bb19f2d8d9524d",
                    "5fd0b37cd7dbbb00f97ba6ce92bf5add",
                    "158f3069a435b314a80bdcb024f8e422",
                    "758874998f5bd0c393da094e1967a72b",
                    "3fe94a002317b5f9259f82690aeea4cd",
                    "432aca3a1e345e339f35a30c8f65edce",
                    "320722549d1751cf3f247855f937b982",
                    "5fd0b37cd7dbbb00f97ba6ce92bf5add",
                    "02522a2b2726fb0a03bb19f2d8d9524d",
                    "7f1de29e6da19d22b51c68001e7e0e54",
                    "42a0e188f5033bc65bf8d78622277c4e",
                    "3988c7f88ebcb58c6ce932b957b6f332",
                    "8f7d807e1f53eff5f9efbe5cb81090fb",
                    "fa83a11a198d5a7f0bf77a1987bcd006"
                ]
            }
        };
        _this.bimTile = _this.parentModule.bimTile;

        _this.bimTile.dataSourceView.on("featuresLoaded", function () {

            $.each(_this.featureGroups, function (i, featureGroup) {

                featureGroup.features = [];
                $.each(featureGroup.ids, function (j, id) {
                    var features = _this.bimTile.dataSourceView.getFeaturesByKey("id", id);
                    if (features.length > 0) {

                        $.each(features, function (j, feature) {
                            featureGroup.features.push(feature);
                        });

                    }
                });
            });

            //
            // console.log(_this.bimTile.dataSourceView.features);
            // console.log(_this.bimTile.dataSourceView.getFeaturesByKey("id", "fe9fc289c3ff0af142b6d3bead98a923"));

            // $.each(_this.bimTile.dataSourceView.getFeaturesByKey("id", "a3c65c2974270fd093ee8a9bf8ae7d0b"), function (i, feature) {
            //     feature.color.alpha = 0;
            // });

            // });

            // _this.bimTile.dataSourceView.tileSet.object.tileLoad.addEventListener(function (tile) {
            //     _this.bimTile.dataSourceView.getFeatures(tile, "id");
            // });


        });

        _this.totalPanel = new Panel({"class": "scModule totalPanel noStyle"});

        _this.totalPanel.cargoCount = _this.renderShCountBlockItem({
            "icon" : _this.app.icons.layer.base64,
            "title": "库房数量"
        });

        _this.totalPanel.goodsCount = _this.renderShCountBlockItem({
            "icon" : _this.app.icons.layer.base64,
            "title": "物料总库存量"
        });

        _this.totalPanel.typeCount = _this.renderShCountBlockItem({
            "icon" : _this.app.icons.layer.base64,
            "title": "物料种类总数"
        });

        _this.totalPanel
            .append(_this.totalPanel.cargoCount)
            .append(_this.totalPanel.goodsCount)
            .append(_this.totalPanel.typeCount)
        ;

        _this.menuPanel = new Panel({"class": "scModule menuPanel noStyle"});

        _this.menuPanel.menus = new TopMenus({
            "app" : _this,
            "list": [
                {
                    "name" : "roof",
                    "label": "屋顶开闭",
                    "icon" : "./img/topmenu/cargo/屋顶开闭.png"
                },
                {
                    "name" : "room",
                    "label": "仓库开闭",
                    "icon" : "./img/topmenu/cargo/仓库开闭.png"
                },
                {
                    "name" : "camera",
                    "label": "视频监控",
                    "icon" : _this.app.icons.camera
                },
                {
                    "name" : "cargos",
                    "label": "温湿监控",
                    "icon" : "./img/topmenu/cargo/温湿监控.png"
                },
                {
                    "name" : "intro",
                    "label": "仓库介绍",
                    "icon" : "./img/topmenu/cargo/仓库介绍.png"
                },
                {
                    "name" : "now",
                    "label": "存量统计",
                    "icon" : "./img/topmenu/cargo/存量统计.png"
                },
                {
                    "name" : "alarm",
                    "label": "库龄预警",
                    "icon" : "./img/topmenu/cargo/库龄预警.png"
                },
                {
                    "name" : "use",
                    "label": "物料领用",
                    "icon" : "./img/topmenu/cargo/物料领用.png"
                },
                {
                    "name" : "link",
                    "label": "管理后台",
                    "icon" : "./img/topmenu/cargo/管理后台.png"
                }
            ]
        });

        _this.menuPanel.append(_this.menuPanel.menus);

        _this.menuPanel.menus.roof.on("click", function () {

            if (!_this.menuPanel.menus.roof.active) {
                _this.closeFeatureGroup(_this.featureGroups.top);
            } else {
                _this.openFeatureGroup(_this.featureGroups.top);
            }

            _this.menuPanel.menus.roof.active = !_this.menuPanel.menus.roof.active;

        });

        _this.menuPanel.menus.room.on("click", function () {

            if (!_this.menuPanel.menus.roof.active) {
                _this.menuPanel.menus.roof.click();
            }


            if (!_this.menuPanel.menus.room.active) {
                _this.closeFeatureGroup(_this.featureGroups.room);
            } else {
                _this.openFeatureGroup(_this.featureGroups.room);
            }

            _this.menuPanel.menus.room.active = !_this.menuPanel.menus.room.active;


        });

        _this.menuPanel.menus.camera.on("click", function () {
            _this.parentModule.modules.workAreaCameraModule.toggle();
        });

        _this.parentModule.modules.workAreaCameraModule.on("toggle", function () {
            _this.menuPanel.menus.camera.active = _this.parentModule.modules.workAreaCameraModule.isOpened;
        });

        _this.menuPanel.menus.cargos.on("click", function () {
            _this.cargos.toggle();
            _this.menuPanel.menus.cargos.active = _this.cargos.isOpened;
        });

        _this.menuPanel.menus.cargos.active = true;

        _this.menuPanel.menus.intro.on("click", function () {
            _this.panels.infoPanel.toggleMinMax();

        });

        _this.menuPanel.menus.link.on("click", function () {
            window.open(_this.app.servers.cargoSystem.login);
        });

        _this.panels.infoPanel.on("toggleMinMax", function () {
            _this.menuPanel.menus.intro.active = !_this.panels.infoPanel.isMined;
        });

        _this.menuPanel.menus.now.on("click", function () {
            _this.panels.nowStaPanel.toggleMinMax();

        });

        _this.panels.nowStaPanel.on("toggleMinMax", function () {
            _this.menuPanel.menus.now.active = !_this.panels.nowStaPanel.isMined;
        });

        _this.menuPanel.menus.alarm.on("click", function () {
            _this.panels.agePanel.toggleMinMax();

        });

        _this.panels.agePanel.on("toggleMinMax", function () {
            _this.menuPanel.menus.alarm.active = !_this.panels.agePanel.isMined;
        });

        _this.menuPanel.menus.use.on("click", function () {
            _this.panels.usePanel.toggleMinMax();

        });

        _this.panels.usePanel.on("toggleMinMax", function () {
            _this.menuPanel.menus.use.active = !_this.panels.usePanel.isMined;
        });


        _this.loadCargos(function () {
            _this.renderCargos(_this.cargosData);
            _this.totalPanel.cargoCount.count.text(_this.cargosData.length);
        });


        _this.getScWarn(function (data) {

            _this.panels.agePanel.ageBlock.head = [
                {
                    "label"    : "序号",
                    "autoCount": function (index) {
                        return String(index + 1000).substring(1, 4);
                    },
                    "col"      : {"width": 40}
                },
                {
                    "label" : "预警类型",
                    "value" : "warnType",
                    "format": function (item, td) {
                        td.text(["库存过低", "库龄超期"][Number(item.warnType) - 1]);
                    },
                    "col"   : {"width": 70}
                },
                {
                    "label": "物料名称",
                    "value": "biiName",
                    "col"  : {"width": 90}
                },
                {
                    "label": "预警描述",
                    "value": "warnDesc"
                }
            ];

            $.each(data.list, function (i, item) {
                _this.panels.agePanel.ageBlock.add(item);
            });
        });

        _this.getScMaterialCollect(function (data) {

            _this.panels.usePanel.useBlock.head = [
                {
                    "label"    : "序号",
                    "autoCount": function (index) {
                        return String(index + 1000).substring(1, 4);
                    },
                    "col"      : {"width": 40}
                },
                {
                    "label": "物料名称",
                    "value": "biiName"
                },
                {
                    "label": "仓库名称",
                    "value": "bwaName",
                    "col"  : {"width": 70}
                },
                {
                    "label": "领用数量",
                    "value": "qty",
                    "col"  : {"width": 70}
                }
            ];

            $.each(data.list, function (i, item) {
                _this.panels.usePanel.useBlock.add(item, function (item, tr) {
                    tr.find("td").eq(0).addClass("rank" + tr.index());
                });
            });
        });

        _this.getScStockQty(function (data) {

            _this.panels.nowStaPanel.nowStaBlock.chart.setOption({
                series: {
                    data: (function () {
                        var list = [];
                        $.each(data.list, function (i, item) {
                            list.push({
                                "name" : item.bwaName,
                                "value": item.stockQty
                            });
                        });
                        return list;
                    }())
                }
            });

            _this.panels.nowStaPanel.nowStaBlock.chart.chart.on("click", "series", function (event) {
                _this.openDetailPanel(event.data.name);
            });

            // var total = 0;
            // $.each(data.list, function (i, item) {
            //     total += item.stockQty;
            // });
            //
            // _this.totalPanel.goodsCount.count.text(total);


        });

        _this.getScMaterialQty(function (data) {
            _this.totalPanel.goodsCount.count.text(data.stockQty);
            _this.totalPanel.typeCount.count.text(data.typeQty);
        });

        _this.app.ui.layout.top.append(_this.totalPanel);
        _this.app.ui.layout.bottom.append(_this.menuPanel);

    }

    var _class = StorehouseModule;

    mhjs.Inherit(_class, Module);

    Object.defineProperties(_class.prototype, {
        "open"                       : {
            value: function () {
                var _this = this;

                _this.bimTile.open();

                _this.layer.open();

                _this.panels.infoPanel.open();
                _this.panels.infoPanel.max();
                _this.panels.nowStaPanel.open();
                _this.panels.nowStaPanel.max();

                _this.panels.agePanel.open();
                _this.panels.agePanel.max();
                _this.panels.usePanel.open();
                _this.panels.usePanel.max();

                _this.totalPanel.open();
                _this.menuPanel.open();

                _this.parentModule.modules.workAreaCameraModule.open();

                // _this.shToggleBlock.menus.camera.trigger("click");
                // _this.shToggleBlock.menus.cargos.trigger("click");

                _this.app.flyVP(_this.viewport);

                _this.isOpened = true;
                _this.trigger("open");
                _this.trigger("toggle");
            }
        },
        "close"                      : {
            value: function () {
                var _this = this;

                _this.bimTile.close();
                _this.layer.close();

                $.each(_this.panels, function (i, panel) {
                    panel.close();
                });

                _this.totalPanel.close();
                _this.menuPanel.close();

                _this.isOpened = false;
                _this.trigger("close");
                _this.trigger("toggle");
            }
        },
        "closeFeatureGroup"          : {
            value: function (featureGroup) {
                var _this = this;

                if (featureGroup.features) {

                    $.each(featureGroup.features, function (i, feature) {

                        //showHide bug fix
                        if (feature.content.batchTable) {
                            feature.show = false;
                        }

                    });
                }
            }
        },
        "openFeatureGroup"           : {
            value: function (featureGroup) {
                var _this = this;

                if (featureGroup.features) {

                    $.each(featureGroup.features, function (i, feature) {

                        //showHide bug fix
                        if (feature.content.batchTable) {
                            feature.show = true;
                        }
                    });
                }
            }
        },
        "getScBwa"                   : {
            value: function (callback) {
                var _this = this;

                _this.app.servers.DC.requests.sc_bwa.send({}, function (json) {
                    if (json.data && json.data.list) {
                        _this.cargosServerData = json.data.list;
                        callback && callback();
                    }
                });


            }
        },
        "getScBii"                   : {
            value: function (callback) {
                var _this = this;

                _this.app.servers.DC.requests.sc_bii.send({}, function (json) {
                    if (json.data) {
                        callback && callback(json.data);
                    }
                });


            }
        },
        "getScBwaTemp"               : {
            value: function (bwa_id, callback) {
                var _this = this;

                _this.app.servers.DC.requests.sc_bwa_temp.send({
                    "bwa_id": bwa_id
                }, function (json) {
                    if (json.data) {
                        callback && callback(json.data);
                    }
                });


            }
        },
        "getScWarn"                  : {
            value: function (callback) {
                var _this = this;
                _this.app.servers.DC.requests.sc_warn.send({}, function (json) {
                    if (json.data) {
                        callback && callback(json.data);
                    }
                });
            }
        },
        "getScStock"                 : {
            value: function (data, callback) {
                var _this = this;
                _this.app.servers.DC.requests.sc_stock.send(data, function (json) {
                    if (json.data) {
                        callback && callback(json.data);
                    }
                });
            }
        },
        "getScStockQty"              : {
            value: function (callback) {
                var _this = this;
                _this.app.servers.DC.requests.sc_stockQty.send({}, function (json) {
                    if (json.data) {
                        callback && callback(json.data);
                    }
                });
            }
        },
        "getScMaterialCollect"       : {
            value: function (callback) {
                var _this = this;
                _this.app.servers.DC.requests.sc_materialCollect.send({}, function (json) {
                    if (json.data) {
                        callback && callback(json.data);
                    }
                });
            }
        },
        "getScMaterialQty"           : {
            value: function (callback) {
                var _this = this;
                _this.app.servers.DC.requests.sc_materialQty.send({}, function (json) {
                    if (json.data) {
                        callback && callback(json.data);
                    }
                });
            }
        },
        "renderScBwaTempItem"        : {
            value: function (bwa) {
                var _this = this;

                var item = new mhjs.Div({
                    "class": "sctempitem"
                });
                var title = new mhjs.Div({
                    "class": "title"
                });

                title.text(bwa.bwa_name);

                var temp = new mhjs.Div({
                    "class": "item"
                });

                var templabel = new mhjs.Div({
                    "class": "label"
                });

                templabel.text("温度:");

                var tempCount = new mhjs.Div({
                    "class": "count"
                });

                tempCount.text("-");

                var tempUnit = new mhjs.Div({
                    "class": "unit"
                });

                tempUnit.text("℃");

                temp
                    .append(templabel)
                    .append(tempCount)
                    .append(tempUnit)
                ;

                var humi = new mhjs.Div({
                    "class": "item"
                });

                var humilabel = new mhjs.Div({
                    "class": "label"
                });

                humilabel.text("湿度:");

                var humiCount = new mhjs.Div({
                    "class": "count"
                });

                humiCount.text("-");

                var humiUnit = new mhjs.Div({
                    "class": "unit"
                });

                humiUnit.text("%");

                humi
                    .append(humilabel)
                    .append(humiCount)
                    .append(humiUnit)
                ;

                item
                    .append(title)
                    .append(temp)
                    .append(humi);


                _this.getScBwaTemp(bwa.bwa_id, function (data) {
                    if (data && data.list && data.list.length > 0) {
                        tempCount.text(data.list[0].temperature);
                        humiCount.text(data.list[0].humidity);
                    }
                });

                return item;
            }
        },
        "renderShCountBlockItem"     : {
            value: function (item) {
                var _this = this;

                var div = new mhjs.Div({"class": "item"});

                div.title = new mhjs.Div({"class": "title"});

                div.title.text(item.title);

                div.icon = new mhjs.Img({"class": "icon"});

                div.icon.attr("src", item.icon);

                div.count = new mhjs.Div({"class": "count"});

                div.count.text(item.count);

                div
                // .append(div.icon)
                    .append(div.title)
                    .append(div.count);

                return div;

            }
        },
        "loadCargos"                 : {
            value: function (callback) {
                var _this = this;

                if (_this.cargosRequest && !_this.isCargosRequestLoaded) {
                    _this.cargosRequest.send({}, function (cargosRequestJson) {


                        if (cargosRequestJson.data && cargosRequestJson.data.list) {

                            _this.cargosData = cargosRequestJson.data.list;

                            _this.app.servers.DC.requests.sc_bwa.send({}, function (cargosServerRequestJson) {

                                if (cargosServerRequestJson.data && cargosServerRequestJson.data.list) {

                                    var cargosServerData = cargosServerRequestJson.data.list;
                                    var temploadedCount = 0;

                                    $.each(_this.cargosData, function (i, cargoData) {

                                        $.each(cargosServerData, function (j, cargoServerData) {
                                            if (cargoData.bwa_code === cargoServerData.bwa_code) {
                                                $.extend(cargoData, cargoServerData);
                                                return false;
                                            }

                                        });

                                        _this.app.servers.DC.requests.sc_bwa_temp.send({
                                            "bwa_id": cargoData.bwa_id
                                        }, function (cargoTempJson) {

                                            temploadedCount++;

                                            if (cargoTempJson.data && cargoTempJson.data.list && cargoTempJson.data.list.length > 0) {
                                                cargoData.temperature = cargoTempJson.data.list[0].temperature;
                                                cargoData.humidity = cargoTempJson.data.list[0].humidity;
                                            }

                                            if (temploadedCount === _this.cargosData.length) {
                                                _this.isCargosRequestLoaded = true;
                                                callback && callback();
                                            }

                                        });


                                    });
                                }


                            });

                        }


                    });
                }


            }
        },
        "renderCargos"               : {
            value: function (cargosData) {
                var _this = this;

                _this.cargos = {
                    "cargos": [],
                    "open"  : function () {
                        $.each(_this.cargos.cargos, function (i, cargo) {
                            cargo.label.object.show = true;
                            cargo.billboard.object.show = true;
                            cargo.temperatureLabel.object.show = true;
                            cargo.humidityLabel.object.show = true;
                        });
                        _this.cargos.isOpened = true;
                    },
                    "close" : function () {
                        $.each(_this.cargos.cargos, function (i, cargo) {
                            cargo.label.object.show = false;
                            cargo.billboard.object.show = false;
                            cargo.temperatureLabel.object.show = false;
                            cargo.humidityLabel.object.show = false;
                        });
                        _this.cargos.isOpened = false;
                    },
                    "toggle": function () {
                        if (_this.cargos.isOpened) {
                            _this.cargos.close();
                        } else {
                            _this.cargos.open();
                        }
                    }
                };

                _this.cargos.isOpened = true;

                $.each(cargosData, function (i, cargoData) {

                    var cargo = {
                        "data": cargoData
                    };

                    cargo.position = new uMap.Position(cargo.data.position);
                    cargo.title = cargo.data.title;

                    // cargo.point = _this.layer.pointPrimitives.add(new uMap.PointOption({
                    //     position                  : cargo.position
                    //     , pixelSize               : 5
                    //     , color                   : ["#ff0"]
                    //     , outlineColor            : ["#000"]
                    //     , outlineWidth            : 2
                    //     , level                   : [0, 1e5]
                    //     , disableDepthTestDistance: Number.POSITIVE_INFINITY
                    // }));

                    cargo.billboard = _this.layer.billboardPrimitives.add(new uMap.BillboardOption({
                        position                  : cargo.position
                        , image                   : "./img/cargomark.png"
                        , verticalOrigin          : "BOTTOM"
                        , width                   : 120
                        , height                  : 100
                        , pixelOffset             : [0, 10]
                        , level                   : [0, 1e5]
                        , disableDepthTestDistance: Number.POSITIVE_INFINITY
                    }));

                    cargo.label = _this.layer.labelPrimitives.add(new uMap.LabelOption({
                        position                  : cargo.position
                        , text                    : cargo.title
                        , font                    : "bold 14px Microsoft SansCN"
                        , fillColor               : ["#fff"]
                        // , style                   : uEarth.LabelStyle.FILL
                        , outlineColor            : ["#000", 0]
                        , outlineWidth            : 5.0
                        , horizontalOrigin        : "CENTER"
                        , verticalOrigin          : "BOTTOM"
                        , pixelOffset             : [0, -62]
                        , level                   : [0, 1e5]
                        , disableDepthTestDistance: Number.POSITIVE_INFINITY
                    }));


                    cargo.temperatureLabel = _this.layer.labelPrimitives.add(new uMap.LabelOption({
                        position                  : cargo.position
                        , text                    : String(cargo.data.temperature.toFixed(1))
                        , font                    : "18px digital"
                        , fillColor               : ["#0f0"]
                        // , style: uEarth.LabelStyle.FILL
                        , outlineColor            : ["#666", 1]
                        , outlineWidth            : 5
                        , horizontalOrigin        : "CENTER"
                        , verticalOrigin          : "BOTTOM"
                        , pixelOffset             : [8, -40]
                        , level                   : [0, 1e5]
                        , disableDepthTestDistance: Number.POSITIVE_INFINITY
                    }));

                    cargo.humidityLabel = _this.layer.labelPrimitives.add(new uMap.LabelOption({
                        position                  : cargo.position
                        , text                    : String(cargo.data.humidity.toFixed(1))
                        , font                    : "18px digital"
                        , fillColor               : ["#0f0"]
                        // , style: uEarth.LabelStyle.FILL
                        , outlineColor            : ["#666", 1]
                        , outlineWidth            : 5
                        , horizontalOrigin        : "CENTER"
                        , verticalOrigin          : "BOTTOM"
                        , pixelOffset             : [8, -15]
                        , level                   : [0, 1e5]
                        , disableDepthTestDistance: Number.POSITIVE_INFINITY
                    }));

                    // cargo.label.on("click", function () {
                    //     cargo.onClick();
                    // });
                    //
                    // cargo.temperatureLabel.on("click", function () {
                    //     cargo.onClick();
                    // });
                    //
                    // cargo.humidityLabel.on("click", function () {
                    //     cargo.onClick();
                    // });
                    //
                    // cargo.billboard.on("click", function () {
                    //     cargo.onClick();
                    // });

                    cargo.onClick = function () {
                        _this.openDetailPanel(cargo.data.bwa_id);
                    };


                    _this.cargos.cargos.push(cargo);

                });

            }
        },
        "openDetailPanel"            : {
            value: function (bwaName) {

                var _this = this;

                _this.panels.nowDetailPanel.nowDetailBlock.clear();
                _this.panels.nowDetailPanel.open();

                _this.getScStock({"bwaName": bwaName}, function (data) {

                    _this.panels.nowDetailPanel.nowDetailBlock.head = [
                        {
                            "label": "仓库名称",
                            "value": "bwaName",
                            "col"  : {"width": 70}
                        },
                        {
                            "label": "物料名称",
                            "value": "biiName"
                        },
                        {
                            "label": "库存数量",
                            "value": "qty",
                            "col"  : {"width": 70}
                        },
                        {
                            "label": "库存单位",
                            "value": "buName",
                            "col"  : {"width": 70}
                        }
                    ];

                    $.each(data.list, function (i, item) {
                        _this.panels.nowDetailPanel.nowDetailBlock.add(item);
                    });
                });
            }
        },
        "loadFeaturesViewports"      : {
            value: function (callback) {
                var _this = this;

                if (_this.featuresViewportsRequest && !_this.isFeaturesViewportsLoaded) {
                    _this.featuresViewportsRequest.send({}, function (json) {
                        if (json.data) {
                            _this.featuresViewports = json.data.list;
                            _this.isFeaturesViewportsLoaded = true;
                            callback && callback();
                        }
                    });
                }

            }
        },
        "renderFeaturesViewportsTree": {
            value: function (list) {

                var _this = this;
                var result = [];

                $.each(list, function (i, item) {
                    if (item.list && item.list.length > 0) {
                        result.push({
                            "title": item.title,
                            "list" : _this.renderFeaturesViewportsTree(item.list)
                        });
                    } else {

                        var tree = new Tree({
                            "title"   : item.title,
                            "autoOpen": true
                        });

                        tree.icon = _this.app.icons.viewport.base64;

                        if (item.videoURL) {
                            tree.icon = _this.app.icons.camera.base64;
                        }

                        tree.ui.titleDiv.on("click", function () {
                            if (item.viewport) {
                                _this.app.flyVP(item.viewport);
                            }

                            if (item.videoURL) {
                                _this.app.videoPlayer.title = item.title;
                                _this.app.videoPlayer.source = item.videoURL;
                                _this.app.videoPlayer.open();
                            }
                        });


                        result.push(tree);
                    }
                });

                return result;

            }
        }
    });

    return _class;

});